package com.da.javatest.leetCode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenlida
 * @date 2019/1/19 14:19
 * @description
 */
public class Code383 {
    public static void main(String[] args) {
        System.out.println(new Code383().canConstruct("aa", "aab"));
    }

    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> map = new HashMap<>(magazine.length());
        for (char c : magazine.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        for (char c : ransomNote.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) - 1);
        }
        return map.values().stream().filter(x -> x < 0).count() <= 0;
    }
}
